package cc.orange.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import cc.orange.utils.CircleImageView;

import cc.orange.R;
import cc.orange.entity.PersonContentEntity;


/**
 * Created by CM on 2022/10/25.
 */

public class DiscoverAdapter extends BaseQuickAdapter<PersonContentEntity.Data, BaseViewHolder> {
    private  onItemsListener listener;
    private int type;
    public DiscoverAdapter(@Nullable List<PersonContentEntity.Data> data) {
        super(R.layout.item_discove, data);
    }

    public void setType(int type){
        this.type = type;
    }
    public void setOnItemsListeners(onItemsListener listener){
        this.listener = listener;
    }
    @Override
    protected void convert(@NonNull BaseViewHolder helper, PersonContentEntity.Data item) {
        CircleImageView discove_img1 = helper.getView(R.id.discove_img1);//头像
        CircleImageView disc_item_img1 = helper.getView(R.id.disc_item_img1);//大图
        ImageView disc_item_img4 = helper.getView(R.id.disc_item_img4);
        ImageView disc_item_click1 = helper.getView(R.id.disc_item_click1);//点击更多

        RelativeLayout disc_item_rel1 = helper.getView(R.id.disc_item_rel1);//年龄控件
        RelativeLayout disc_item_rel2 = helper.getView(R.id.disc_item_rel2); //真人标志
        RelativeLayout disc_item_rel3 = helper.getView(R.id.disc_item_rel3); //
        TextView disc_item_text4 = helper.getView(R.id.disc_item_text4); //私信点击
        if(type == 1){
            disc_item_img4.setVisibility(View.VISIBLE);
            disc_item_click1.setVisibility(View.VISIBLE);
            disc_item_click1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    listener.itemsListener1(helper.getLayoutPosition());
                }
            });

            discove_img1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    listener.itemsListener3(helper.getLayoutPosition());
                }
            });

            disc_item_text4.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    listener.itemsListener2(helper.getLayoutPosition());
                }
            });
        }else{
            disc_item_img4.setVisibility(View.GONE);
            disc_item_click1.setVisibility(View.GONE);
            disc_item_rel1.setVisibility(View.GONE);
            disc_item_rel2.setVisibility(View.GONE);
            disc_item_rel3.setVisibility(View.GONE);
        }

        ImageView disc_item_img2 = helper.getView(R.id.disc_item_img2);//点赞图标
        TextView discove_img2 = helper.getView(R.id.discove_img2);//圆点

//        color_ff1451


        TextView disc_item_text3 = helper.getView(R.id.disc_item_text3); //点赞文字

            disc_item_img2.setImageResource(item.getStatus() == 0 ? // 0 已点赞
                    R.drawable.icon_disc_img5 : R.drawable.icon_disc_img6);
            disc_item_text3.setTextColor(mContext.getResources().getColor(
                    item.getStatus() == 0 ? R.color.color_ff3062 : R.color.color_777777));

        helper.setText(R.id.disc_item_text1,""+item.getName());//用户名
        helper.setText(R.id.disc_item_text5,item.getCreateTime());//时间
        helper.setText(R.id.disc_item_text2,item.getDynamic());//内容
        Glide.with(mContext).load(item.getPhoto())
                .into(discove_img1);
        if(null == item.getImage() || TextUtils.isEmpty(item.getImage())){
            disc_item_img1.setVisibility(View.GONE);
        }else{
            disc_item_img1.setVisibility(View.VISIBLE);
            Glide.with(mContext).load(item.getImage())
                    .into(disc_item_img1);
        }


//        disc_item_img1.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                listener.itemsListener3(helper.getLayoutPosition());
//            }
//        });

        disc_item_text3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.itemsListener4(helper.getLayoutPosition());
            }
        });
    }

    public interface onItemsListener{
        void itemsListener1(int position);
        void itemsListener2(int position);
        void itemsListener3(int position);
        void itemsListener4(int position);
    }
}
